package org.msfj.toilets;

import org.msfj.authority.client.EnableAuthorityClient;
import org.msfj.common.context.SpringContextHelper;
import org.msfj.toilets.config.ToiletConfig;
import org.msfj.toilets.socket.tcp.TioTcpHandler;
import org.msfj.toilets.socket.udp.TioUdpHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RestController;
import org.tio.core.udp.UdpServer;
import org.tio.core.udp.UdpServerConf;
import org.tio.server.ServerGroupContext;
import org.tio.server.TioServer;
import tk.mybatis.spring.annotation.MapperScan;

/**
 * @Description:
 * @Author: like
 * @Date: 2018-03-09 10:58
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@RestController
@SpringBootApplication
@MapperScan(basePackages = {"org.msfj.toilets.data.mapper"})
@ComponentScan(basePackages = "org.msfj")
@EnableFeignClients("org.msfj.*.feign")
@EnableAuthorityClient
@EnableScheduling
public class ToiletsApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(ToiletsApplication.class, args);
        ToiletConfig toiletConfig = SpringContextHelper.getBean(ToiletConfig.class);
        TioTcpHandler tioTcpHandler = new TioTcpHandler(toiletConfig);
        ServerGroupContext serverGroupContext = new ServerGroupContext(tioTcpHandler,null);
        TioServer tioServer = new TioServer(serverGroupContext);
        tioServer.start(null,toiletConfig.getTcpPort());

        TioUdpHandler tioUdpHandler = new TioUdpHandler(toiletConfig);
        UdpServerConf udpServerConf = new UdpServerConf(toiletConfig.getUdpPort(), tioUdpHandler, 5000);
        UdpServer udpServer = new UdpServer(udpServerConf);
        udpServer.start();
    }
}
